<% /**
	* 
	* 
	* Displays a workout
	*
	* @author Samson and Oren
	*/
%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="b1w1nn1ng.crossf1t.db.*"%>
    <%@page import="b1w1nn1ng.crossf1t.gui.*"%>
    <%@page import="b1w1nn1ng.crossf1t.business.*"%>
    <%@page import="java.util.*"%>
    

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%  
User user = (User) session.getAttribute("user");
String day;
day = (String) request.getParameter("date");
session.setAttribute("user", user);
%>
<html>
	<head>
		<title> Display Workout </title>
		<jsp:include page="/detectBrowser.jsp" />
		<link rel="stylesheet" type="text/css" href="/crossfit/css/displayWorkout.css" />
	</head>
	<body>
	<div id="container">
	<jsp:include page="/navbar.jsp" />	
		<h1> Display Workout</h1> <hr />
		
		Workout from <%= day %> 
		<br /><br />
		<%= user.getUsername() + "'s Workout" %> <br />
		<%
			Calendar displayCal = Workout.parseDate(day);
			//Workout displayWorkout = Workout.getWorkOut(user.getId(), displayCal);
			Workout displayWorkout = Workout.getTestWORKOUT();
			String type = displayWorkout.getType();
		%>
		<br />
		<table id="workout" border = 1>
		<%=
			
			"Workout type: " + type + "<br/>" +
			"Prescribed: " %>   
			<% if(displayWorkout.isPrescribed())
				out.print("Yes");
			else
				out.print("No");
			%>
			<%= 
			"<br/>"
			%>
			<% 
			//Exercise exercises[] = displayWorkout.getExercises(); 
			ArrayList<Exercise> exercises = displayWorkout.getExercises();
			if(type.equals("Tabata")){
				%>
				<%= 
			"Exercise type: " + exercises.get(0).getType() +
			"<br/>Tabata Score: " + ((Tabata)displayWorkout).getScore() +
			"<br/><br/><tr><td>Round</td><td>Weight</td><td>Reps</td</tr>    "
			%>
			
			<% 
			for(int i = 0; i < displayWorkout.getExercises().size(); i++){
			%>
			<%= "<tr>"+
			"<td>" + (i+1) + "</td>" +
			"<td>" + exercises.get(i).getWeights() + "</td>" +
			"<td>" + exercises.get(i).getReps() + "</td>"+
			
			"</tr>"
			%>
		<%	}//end for loop
			}//end if statement
			else if(type.equals("AMRAP")){
		%>

		<%= 
			"Time Limit: " + ((AMRAP)displayWorkout).getTimeLimit() +
			"<br/>" +
			"Rounds Completed: " + ((AMRAP)displayWorkout).getRoundsCompleted() +
			"<br/>" +
			"<tr><td>Exercise</td><td>Reps</td</tr>    "
			%>
			
			<% 
			for(int i = 0; i < displayWorkout.getExercises().size(); i++){
				System.out.println("Inside displayWorkout.jsp: exercises.get(i): " + exercises.get(i) );
			%>
			<%= "<tr>"+
			"<td>" + exercises.get(i) + "</td>" +
			"<td>" + exercises.get(i).getReps() + "</td>"+
			
			"</tr>"
			%>
		<%	}//end for loop
			}//end if statement
			else if(type.equals("Timed")){
		%>

		<%= 
			"Time: " + ((Timed)displayWorkout).getTime() +
			"<br/>" +
			"Rounds Completed: " + ((AMRAP)displayWorkout).getRoundsCompleted() +
			"<br/>" +
			"<tr><td>Exercise</td><td>Reps</td</tr>    "
			%>
			
			<% 
			for(int i = 0; i < displayWorkout.getExercises().size(); i++){
			%>
			<%= "<tr>"+
			"<td>" + exercises.get(i) + "</td>" +
			"<td>" + exercises.get(i).getReps() + "</td>"+
			
			"</tr>"
			%>
		<%}//end for loop
			}//end if statement
			else if(type.equals("Timed"))
			{
				out.print("ERROR, Type of Workout not recognized");
			}
		%>
		
		</table>
		</div>
	</body>
</html>


